package com.rules.admin.domain;

import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;

import org.springframework.lang.Nullable;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityConfig;

public abstract class ResourceMatcher implements Serializable {
    private static final long serialVersionUID = 436653742917484012L;
    private SysResource resource;

    public ResourceMatcher() {
    }

    public abstract boolean matches(HttpServletRequest var1);

    public SysResource getResource() {
        return this.resource;
    }

    public ResourceMatcher setResource(SysResource resource) {
        this.resource = resource;
        return this;
    }

    public List<String> getChildResourceUrls() {
        Iterable<String> urls = Iterables.transform(this.resource.getChildren(), new Function<SysResource, String>() {
            @Nullable
            public String apply(@Nullable SysResource resource) {
                return resource != null ? resource.getUrl() : null;
            }
        });
        return Lists.newArrayList(urls);
    }

    public List<ConfigAttribute> getConfigAttributes() {
        ArrayList<ConfigAttribute> configAttrs = Lists.newArrayList();
        configAttrs.add(new SecurityConfig(this.resource.getUrl()));
        return configAttrs;
    }
}